package br.com.agenda.controller;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import br.com.agenda.entity.Cliente;

@Component
public class ClienteValidator implements Validator {

	public boolean supports(Class<?> clazz) {
		return Cliente.class.isAssignableFrom(clazz);
	}

	public void validate(Object target, Errors errors) {
		Cliente cliente = (Cliente) target;

		// Campos obrigatorios
		// if (GenericValidator.isBlankOrNull(cliente.getDescricao())) {
		// errors.reject("baia.msg.erro.baia.nao.informada");
		// }

		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "nome",
				"cadastro_cliente.msg.nome_tamanho_invalido");

	}

}
